<?php


namespace App\Services;

const URL = "https://bms.jsyixin.com";
//const URL = "http://xinzhi_bms.jsyixin.com";

class StudentService
{

    public function getToken(){
        $url = URL . "/api/signUp";
        $params = [
            'account'=>'admin',
            'password'=>'@xinzhi#2022$qwe',
            'smsCode'=>888888
        ];
//        $params = [
//            'account'=>'chengdu',
//            'password'=>'123456',
//            'smsCode'=>888888
//        ];
        $administer = create_curl($url,$params);
        $list = jsonDecode($administer);
        if($list['status'] == 1){
            return $list['data']['token'];
        }else{
            return "";
        }
    }

    /**
     * 返回下载复检名单链接
     * @param $input
     */
    public function exportRecheckUnfinished($input){
        $url = URL . "/api/recheck/exportRecheckRoster";
         $param = '?token='.$input['token'].'&batch_id='.$input['batch_id'].'&type='.$input['type'].'&status=0';
         return $url.$param;
    }
    //获取学段
    public function getSectionList($input){
        $url = URL . "/api/level/getSectionList";
        $params = [
            'token'=>$input['token'],
            'school_id'=>$input['school_id']
        ];
        $administer = create_curl($url,$params);
        $list = jsonDecode($administer);
        if($list['status']==1){
            return $list['data'];
        }else{
            return "";
        }
    }
    //获取年级
    public function getGradeList($input){
        $url = URL . "/api/level/getGradeList";
        $params = [
            'token'=>$input['token'],
            'section_id'=>$input['section_id'],
            'type' =>2
        ];
        $administer = create_curl($url,$params);
        $list = jsonDecode($administer);
        if($list['status']==1){
            return $list['data'];
        }else{
            return "";
        }
    }
    //获取班级
    public function getClassList($input){
        $url = URL . "/api/level/getClassList";
        $params = [
            'token'=>$input['token'],
            'grade_id'=>$input['grade_id'],
        ];
        $administer = create_curl($url,$params);
        $list = jsonDecode($administer);
        if($list['status']==1){
            return $list['data'];
        }else{
            return "";
        }
    }
    // 获取学校名称
    public function getSchoolInfo($token,$title){
        $url = URL . "/api/school/getList";
        $params = [
            'token'=>$token,
            'title'=>$title
        ];
        $administer = create_curl($url,$params);
        $list = jsonDecode($administer);
        if($list['status']==1){
            return $list['data']['list'];
        }else{
            return "";
        }
    }
    // 获取学校的计划
    public function getSchoolPlan($token,$title){
        $url = URL ."/api/schoolPlan/getList";
        $params = [
            'token'=>$token,
            'school_title'=>$title
        ];
        $administer = create_curl($url,$params);
        $list = jsonDecode($administer);
        if($list['status']==1){
            return $list['data']['list'];
        }else{
            return "";
        }
    }

    /**
     * 获取计划的列表
     * @param $token
     * @param $title
     * @return mixed|string
     */
    public function getSchoolRecheckPlan($token,$title){
        $url = URL ."/api/recheck/getBatchList";
        $params = [
            'token'=>$token,
            'school_title'=>$title,
            'type'=>1
        ];
        $administer = create_curl($url,$params);
        $list = jsonDecode($administer);
        if($list['status']==1){
            return $list['data']['list'];
        }else{
            return "";
        }

    }
    /**
     * 获取未完成名单
     * @param $input
     * @return mixed|string
     */
    public function  getEvaluationProgress($input){
        $url = URL ."/api/schoolPlan/getEvaluationProgress";
        $params = [
            'token'=>$input['token'],
            'plan_id'=>$input['plan_id'],
            'is_finish'=> '',
            'school_id'=>$input['school_id'],
            'limit' => 10000,
            'section_title'=> $input['section_title']??'',
            'grade_title'=>$input['grade_title']??'',
            'class_title'=> $input['class_title']??'',
            'abnormal_status'=> '',
            'page' => 1
        ];
        $administer = create_curl($url,$params);
        $list = jsonDecode($administer);
        if($list['status'] == 1){
            return $list['data'];
        }else{
            return "";
        }
    }
    // 查看未完成名单的数据
    public function getUnfinishList($data,$input){
        $page = $input['page'] ?? 1;
        $limit = $input['limit']??10;
        $list = [];
        //将数据根据uid进行整合
        foreach ($data['list']['list'] as $v){
            $list[$v['uid']][] = $v;
        }
        $unfinishList = [];
        $dataList = [];
        // 根据uid 进行查看学生的情况
        if ($input['status'] ==1) {
            foreach ($list as $v) {
                if (count($v) == 1) { // 只有一条学生已作答和未作答
                    if ($v[0]['is_finish'] == '') { // 调取未作答的数据
                        $unfinishList['list']['list'][] = $v[0];
                    }
                }
                continue;
            }
        }
        if ($input['status'] ==2) { //查看异常作答名单
            foreach ($list as $v) {
                if (count($v) > 1) { //必须是1次以上
                    foreach ($v as $item) { //进行处理异常作答
                        if ($item['is_finish'] == '') {
                            $unfinishList['list']['list'][] = $item;
                        }
                        continue;
                    }
                }
                continue;
            }
        }
        if (!empty($unfinishList)){
            $dataList['list']['totalNumber'] = count($unfinishList['list']['list']);
            $dataList['list']['page'] = $page;
            $offset  = ($page - 1) * $limit;
            $dataList['list']['list'] = array_splice($unfinishList['list']['list'],$offset,$limit);
        }
        return $dataList;
    }
    /**
     * 复检批次下的复检名单
     * @param $input
     * @return mixed|string
     */
    public function getRecheckRosterList($input){
        $url = URL ."/api/recheck/getRecheckRosterList";
        $params = [
            'token'=>$input['token'],
            'batch_id'=>$input['batch_id'],
            'type'=>1,
            'status'=>0,
            'limit' => 10,
            'section_title'=> $input['section_title'],
            'grade_title'=>$input['grade_title'],
            'class_title'=> $input['class_title'],
            'page' => isset($input['page'])?$input['page']:1
        ];
        $administer = create_curl($url,$params);
        $list = jsonDecode($administer);
//        x($list);
        if($list['status'] == 1){
            return $list['data'];
        }else{
            return "";
        }
    }
    //
    //http://xinzhi_bms.jsyixin.com/api/schoolPlan/checkExportUnfinished?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOnsidWlkIjo1LCJhdXRoX3Rva2VuIjoiMTJlMmJjYjYtNjlhMy00YjYyLWI2ZWQtNDc2ZmZiOGE3YjlhIiwic3lzdGVtUGFybSI6ImV5SjBlWEFpT2lKS1YxUWlMQ0poYkdjaU9pSklVekkxTmlKOS5leUprWVhSaElqb2lWVXhPVWpoNWVHVjBlbkU1VEhGbFVVVlRPR2xpWkRoMlRVOVJVMVYxVldWeFNUQXlORGRzYkdGWFp6Wm9kVkpOTkZKeWRrODNhbTBsTWtaTVMyMXBZMk5pZDA1bmRYQnFTbFpvUVZwdVJVUnphbWRSWWxCSmVuRXdKVEpHZDIxcWVUbFNUblZxTWtKNlNUSlBiazQzY205bmRXYzJUMUZtUm5BMFFVc2xNa1k0VkRCWk4yNHhWVVUzWVhSNk5UTjVKVEpDTTJSM05qSlhibGhIYUdjbE0wUWxNMFFpTENKbGVIQWlPakUyTmpFeU9UWTBNakI5LmtQR0JOVXU2SlN0dFhDTzhUM0NpTWRkOF9yemY1SVZiMVkwUVFTOEhZR1EifSwiZXhwaXJlIjo0MzAwMCwiY3VycmVudFRpbWUiOjE2NjEyNTMyMjB9.6gVc6n4dmBlsUKE2LNZZmel8x6fPwLMd-oLb9g5wkMo&plan_id=3657&school_id=3772
    /**
     * 获取未完成名单的地址
     * @param $input
     * @return mixed|string
     */
    public function  checkExportUnfinished($input){
        $url = URL ."/api/schoolPlan/checkExportUnfinished";
        $params = [
            'token'=>$input['token'],
            'plan_id'=>$input['plan_id'],
            'school_id'=>$input['school_id']
        ];
//        x($params);
        $administer = create_curl($url,$params);
        $list = jsonDecode($administer);
        if($list['status']==1){
            return $list['data'];
        }else{
            return "";
        }
    }

    /**
     * 获取异常作答的名单
     * @param $input
     * @return mixed|string
     */
    public function checkExportExceptionData($input){
        $url = URL ."/api/schoolPlan/checkExportExceptionData";
        $params = [
            'token'=>$input['token'],
            'plan_id'=>$input['plan_id'],
            'school_id'=>$input['school_id']
        ];
//        x($params);
        $administer = create_curl($url,$params);
        $list = jsonDecode($administer);
        if($list['status']==1){
            return $list['data'];
        }else{
            return "";
        }
    }
}